# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

import os
from types import SimpleNamespace


def print_and_run(cmd):
  print(cmd)
  os.system(cmd)


print_and_run("bazel build cc/appcoin2/support/order_latency:dumper --config opt")

feed_machine = 'feed-05.ap-northeast-1.aws'

items = []


def add_all_expiry(strat_machine, strat_account, mea, recipe, spot_symbol):
  for expiry in ['QUARTER', 'NEXT_WEEK', 'WEEK']:
    items.append(
        SimpleNamespace(
            strat_machine=strat_machine,
            strat_account=strat_account,
            mea=mea,
            recipe=recipe,
            symbol=f'{spot_symbol}.{expiry}',
            duration='P5D',
            end='2020-06-18',
        ))


# huobi donggu
for base in ['BCHSV', 'XRP', 'ETC', 'ETH']:
  add_all_expiry('strategy-42.ap-northeast-1.huobi',
                 'prestoinvt69',
                 'Futures.Huobi.v1',
                 'incremental',
                 f'{base}-USD')

# huobi taekwon 1
for base in ['BCHABC', 'EOS']:
  add_all_expiry('strategy-43.ap-northeast-1.huobi',
                 'prestoinvt53',
                 'Futures.Huobi.v1',
                 'incremental',
                 f'{base}-USD')

# huobi taekwon 2
for base in ['BTC', 'LTC']:
  add_all_expiry('strategy-43.ap-northeast-1.huobi',
                 'prestoinvt53',
                 'Futures.Huobi.v1',
                 'incremental',
                 f'{base}-USD')

# okex donggu
for base in ['BCHABC', 'BTC', 'EOS', 'LTC']:
  add_all_expiry('strategy-58.aliyun-cn-hongkong.okex',
                 'prestoinvt22',
                 'Futures.Okex.v3',
                 'realtime',
                 f'{base}-USD')

# list of (strat_account, strat_machine, mea, recipe, product)

cmd = 'parallel --jobs 0 --progress :::'
for item in items:
  cmd += (f' \\\n  "srun -N1 -n1 ./bazel-bin/cc/appcoin2/support/order_latency/dumper'
  f' --product {item.symbol} --feed_machine {feed_machine} --mea {item.mea} --recipe {item.recipe}'
  f' --strat_account{item.strat_account} - -strat_machine{item.strat_machine}'
  f' --duration {item.duration} --end {item.end}"'

print_and_run(cmd)
print_and_run('rsync out/latency-dataset ../coin_binary -avg --delete')
